package com.zhou.yygh.hosp.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhou.yygh.common.exception.YyghException;
import com.zhou.yygh.common.result.ResultCodeEnum;
import com.zhou.yygh.hosp.mapper.HospitalSetMapper;
import com.zhou.yygh.hosp.service.HospitalSetService;
import org.springframework.stereotype.Service;
import zhou.hospital.model.hosp.HospitalSet;
import zhou.hospital.vo.order.SignInfoVo;

@Service
public class HospitalSetServiceImpl extends ServiceImpl<HospitalSetMapper, HospitalSet> implements HospitalSetService {
    @Override
    public String getSignKey(String hoscode) {
        QueryWrapper<HospitalSet> wrapper = new QueryWrapper<>();
        wrapper.eq("hoscode",hoscode);
        HospitalSet hospitalSet = baseMapper.selectOne(wrapper);
        return hospitalSet.getSignKey();
    }

    @Override
    public SignInfoVo getSignInfoVo(String hoscode) {
        SignInfoVo signInfoVo = new SignInfoVo();
        QueryWrapper<HospitalSet> wrapper = new QueryWrapper<>();
        wrapper.eq("hoscode",hoscode);
        HospitalSet hospitalSet = baseMapper.selectOne(wrapper);
        if(hospitalSet == null){
            throw new YyghException(ResultCodeEnum.HOSPITAL_OPEN);
        }signInfoVo.setSignKey(hospitalSet.getSignKey());
       signInfoVo.setApiUrl(hospitalSet.getApiUrl());
       return signInfoVo;

    }
}
